import tkinter as tk
import network
import regular
import student
import chat108  # Import the new chat108 module

root = tk.Tk()
root.title("工具箱")

def center_window(root):
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    
    width = screen_width // 3 * 2
    height = screen_height // 3 * 2
    x = (screen_width - width) // 2
    y = (screen_height - height) // 2
    
    root.geometry(f"{width}x{height}+{x}+{y}")

center_window(root)

root.update_idletasks()

#容器
tool_name_frame = tk.Frame(root, borderwidth=1, relief=tk.SOLID)
tool_name_frame.place(x=0, y=0, width=100, height=root.winfo_height())
#top_frame.pack(side=tk.LEFT)

#输入框
#entry = tk.Entry(top_frame)
#entry.place(x=0, y=0, width=100, height=30)
#entry.pack(side=tk.LEFT)


# 强制更新窗口以确保小部件布局完成
#root.update_idletasks()

#print(entry.winfo_width())

#tk.Text(tool_name_frame,).place(x=0, y=0, width=200, height=root.winfo_height())
#按钮

root.update_idletasks()

right_panel = tk.Frame(root, borderwidth=1, relief=tk.SOLID)
right_panel.place(x=100, y=0, width=root.winfo_width() - 100, height=root.winfo_height())

root.update_idletasks()

network_button = tk.Button(tool_name_frame, text="网络测试", 
                           command=lambda: network.NetworkPanel.instance(right_panel).show_network_panel())
#button.place(x = entry.winfo_width() + 10, y=0)
network_button.pack(side=tk.TOP)

regular_button = tk.Button(tool_name_frame, text="正则测试", 
                           command=lambda: regular.RegularPanel.instance(right_panel).show_regular_panel())
#button.place(x = entry.winfo_width() + 10, y=0)
regular_button.pack(side=tk.TOP)

translate_button = tk.Button(tool_name_frame, text="机器翻译", 
                           command=lambda: print("机器翻译"))
translate_button.pack(side=tk.TOP)

speech_to_text_button = tk.Button(tool_name_frame, text="语音识别", 
                           command=lambda: print("语音识别"))
speech_to_text_button.pack(side=tk.TOP)

text_to_speech_button = tk.Button(tool_name_frame, text="语音合成", 
                           command=lambda: print("语音合成"))
text_to_speech_button.pack(side=tk.TOP)

text_to_video_button = tk.Button(tool_name_frame, text="文生视频", 
                           command=lambda: print("文生视频"))
text_to_video_button.pack(side=tk.TOP)

button1 = tk.Button(tool_name_frame, text="学生信息", 
                           command=lambda: student.Student.instance(right_panel).show_student_panel())
button1.pack(side=tk.TOP)

# 在已有的按钮下方添加新的按钮

chat108_button = tk.Button(tool_name_frame, text="chat108", 
                            command=lambda: chat108.Chat108Panel.instance(right_panel).show_chat108_panel())
chat108_button.pack(side=tk.TOP)

network_button.invoke()

root.mainloop()